<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Banner;
use app\common\model\goods\Goods as GoodsGoods;
use app\common\model\product\Category;
use app\common\model\product\Product as ProductProduct;

/**
 * 产品接口
 * @ApiInternal
 */
class Product extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * @Author LK
     * @ApiTitle (产品分类)
     * @ApiMethod (GET)
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function category()
    {
        $lists = Category::all();
        $this->success('请求成功', $lists);
    }

    /**
     * @Author LK
     * @ApiTitle (产品授权区域)
     * @ApiMethod (GET)
     * @ApiParams (name="category_id", type="integer", required=true, sample="", description="分类ID")
     * @ApiParams (name="province", type="string", required=true, sample="", description="省")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function auth_area()
    {
        $params = request()->param();
        extract($params);
        $city = ProductProduct::all(['category_id' => $category_id, 'province' => $province, 'region' => 1]);
        $area = ProductProduct::all(['category_id' => $category_id, 'province' => $province, 'region' => 2]);
        $this->success('请求成功',compact('city','area'));

    }
    /**
     * @Author LK
     * @ApiTitle (商品详情)
     * @ApiMethod (GET)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="ID")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function info()
    {
        $id = request()->param('id');
        $goods = ProductProduct::get($id, ['spec']);
        $this->success('请求成功', $goods);
    }
}
